package com.example.demo.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.util.Base64;

/**
 * @program: demo_sb
 * @description:
 * @author: luojm
 * @create: 2018-10-12 15:19
 */
@RestController
@RequestMapping(value = "/file")
public class FileTest {
    /**
     * @param path
     * @return String
     * @description 将文件转base64字符串
     * @date 2018年3月20日
     * @author changyl
     * File转成编码成BASE64
     */
    @RequestMapping(value = "/test")
    public static String multipartFileToBase64(MultipartFile file) {
        String base64 = null;
        try {
            base64 = Base64.getEncoder().encodeToString(file.getBytes());
        } catch (Exception e) {
            e.printStackTrace();
        }
        System.err.println(base64);
        return base64;
    }


}
